//
//  BaseTableViewController.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/8.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "BaseTableViewController.h"
#import "LogOnViewController.h"
#import "CYXNavigationController.h"

@interface BaseTableViewController ()

@end

@implementation BaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.isHideTitle = YES;
    [self setupUI];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (self.isHideTitle) {
        self.navigationItem.title = @"";
    }else{
        self.navigationItem.title = self.title;
    }
        if (!self.isIgnoreLogon) {
            [LCNotifiCenter addObserver:(self) selector:(@selector(goToLogOn)) name:(@"UserNeedLogOn") object:nil];
        }
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [LCNotifiCenter removeObserver:self name:@"UserNeedLogOn" object:nil];
}

- (void)setupUI{
    self.view.backgroundColor = MainColor;
}

- (void)leftNavItemClick:(id)sender{
    
}

- (void)rightNavItemClick:(id)sender{
    
}


- (void)setRightNavItem:(NSString *)title font:(UIFont *)font color:(UIColor *)color icon:(NSString *)icon{
    
    self.navigationItem.rightBarButtonItem = [self getBarItem:title font:font color:color icon:icon sel:@selector(rightNavItemClick:)];
}

- (void)setLeftNavItem:(NSString *)title font:(UIFont *)font color:(UIColor *)color icon:(NSString *)icon{
    
    self.navigationItem.leftBarButtonItem = [self getBarItem:title font:font color:color icon:icon sel:@selector(leftNavItemClick:)];
}

- (UIBarButtonItem *)getBarItem:(NSString *)title font:(UIFont *)font color:(UIColor *)color icon:(NSString *)icon sel:(SEL)sel{
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0,0,80,30)];
    [btn addTarget:self action:sel forControlEvents:(UIControlEventTouchUpInside)];
    if (title) {
        [btn setTitle:title forState:(UIControlStateNormal)];
    }
    if (icon) {
        [btn setImage:[UIImage imageNamed:icon] forState:(UIControlStateNormal)];
    }
    if (font){
        btn.titleLabel.font = font;
    }
    if (color){
        btn.titleLabel.textColor = color;
    }
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

- (void)goToLogOn{
    LogOnViewController *vc = LoadVCFormXib(LogOnViewController);
    CYXNavigationController *navC = [[CYXNavigationController alloc]initWithRootViewController:vc];
    [navC setBarStyle:YES];
    //设置模态视图弹出样式
    navC.modalPresentationStyle = UIModalPresentationOverFullScreen;

    [kAppDelegate.getCurrentVC presentViewController:navC animated:YES completion:nil];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
}

- (void)dealloc{
    [LCNotifiCenter removeObserver:self];
}

@end
